using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

public class ChangeScenePopup : MonoBehaviour
{
	public Text title;
	public RectTransform content;
	public ButtonID buttonUsed;
	public SceneInfo sceneInfo;

	private List<GameObject> buttons = new List<GameObject>();

	public void Init(SceneID[] _scenes)
	{
		GameObject tempButton;
		foreach (SceneID id in _scenes)
		{
			tempButton = PoolManager.Instance.GetFromPool(buttonUsed.ToString());
			ScreensManager.Instance.SetParent(tempButton, content);

			SceneInfo.Info info = GetSceneInfo(id);
			tempButton.GetComponent<ButtonSimple>().Setup(info.name);
			buttons.Add(tempButton);
		}

		title.text = sceneInfo.scenesInfos[0].GetTitle();
	}

	private SceneInfo.Info GetSceneInfo(SceneID _id)
	{
		foreach (SceneInfo.Info info in sceneInfo.scenesInfos)
		{
			if (info.id == _id)
			{
				return info;
			}
		}

		return null;
	}

	public void OnClick_Close()
	{
		if (PoolManager.Exists())
		{
			foreach (GameObject go in buttons)
			{
				PoolManager.Instance.ReturnToPool(go);
			}
		}

		ScreensManager.Instance.RemovePopup(gameObject);
	}
}
